package com.lcxw.hxzbadmin.dao.dbmanagermapper;

import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

@Mapper
@Component
public interface DbManagerMapper {

    @Select("select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA=(select database())")
    List<String> selectAllTables();

    @Select({"SELECT (data_length+index_length) AS size , data_free AS free",
        "FROM information_schema.tables",
        "WHERE table_schema=(SELECT DATABASE()) AND table_name=#{tableName};"})
    Map<String,Integer> selectTableSize(String tableName);

    @Update("Alter table #{tableName} engine=innodb")
    int optimizeTable(String tableName);

}
